package com.project.thread.homework;



public class People extends Thread{
    private String name;

    private long time;

    private JiaoZi x;

    public People(String name, JiaoZi x, long time) {
        this.name = name;
        this.x = x;
        this.time = time;
    }


    public void run() {

        int num = 0;
        while (true) {
            synchronized (this.x) {
                if (this.x.getJz() == 0) {
                    break;
                }
                num++;
                this.x.setJiaozi(this.x.getJz() - 1);
                System.out.println(this.name + "吃了第" + num + "个饺子！");
            }
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {

                e.printStackTrace();
            }
        }
    }
}

